// pages/login/loginIndex/loginIndex.js
import login from "../../../config/https/login"

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		tell: '',
		isTell: false,
		code: '',
		userInfo: null,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {
		const image = "";
		return {
			imageUrl: image,
			path: this.route
		}
	},

	// 获取手机号
	getTellNum: function(e) {
		let that = this;
		let tell = e.detail.value;
		let isTell = false;
		// 正则匹配手机号
		let res = /^1[3578][0-9]\d{8}/;
		if (res.test(tell)) {
			isTell = true;
		}
		that.setData({
			tell: tell,
			isTell: isTell
		})
	},

	// 获取输入的验证码
	getCodeNum: function(e) {
		let that = this;
		let code = e.detail.value;
		that.setData({
			code: code
		})
	},

	// 登录loading
	loginLoadingTap: function() {
		wx.showLoading({
			title: '登录中...'
		});
	},

	// 登录
	loginTap: function() {
		wx.switchTab({
			url: '/pages/index/index'
		})
	},

	// 微信登录
	sysLogin: function(e) {
		wx.emitter.emit('sys.getUserInfo.result', e.detail);
		login().then((res) => {
			wx.showToast({
				title: '登录成功！',
				success: (res) => {
					this.data.userInfo = e.detail;
					if (getCurrentPages().length > 1) {
						wx.navigateBack();
					} else {
						wx.switchTab({
							url: '/pages/index/index'
						});
					}
				}
			});
		}, () => {
			wx.showToast({
				title: '登录失败，请重新登录！',
				icon: "none"
			});
		})
	},


});
